package com.hangzhou.xyj.ui.activity;

import android.content.Intent;
import android.widget.EditText;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.model.type.EIntentTagType;
import com.hangzhou.xyj.net.handler.SavePublishHandler;
import com.hangzhou.xyj.net.http.HttpLoader;
import com.hangzhou.xyj.net.request.SavePublishReq;
import com.hangzhou.xyj.ui.activity.base.BaseActivity;
import com.hangzhou.xyj.ui.widget.CommonTitleBarView;
import com.hangzhou.xyj.utils.StringUtil;
import com.hangzhou.xyj.utils.ToastUtil;
import com.hangzhou.xyj.utils.constants.DataKey;

/**
 * Created by yaohuix on 2016/4/21  10:14
 * <p/>
 * 说明：报名，订票 页面
 */
public class SignUpActivity extends BaseActivity {

    private EditText mEtContent;
    private int mIntentTag;
    private int mActionId;

    @Override
    public void initIntentData(Intent intent) {
        mIntentTag = intent.getIntExtra(DataKey.INTENT_TAG, -1);
        mActionId = intent.getIntExtra(DataKey.OBJ_ID, -1);

    }

    @Override
    public void initDatas() {

    }

    @Override
    public void initTop() {
        enableRightNav(true, "确定");
        switch (EIntentTagType.valueOf(mIntentTag)) {
            case TAG_FIND_SHOW://发现-演出
                enableTitle(true, "订票");
                break;
            case TAG_FIND_ACTION://发现-活动
            default:
                enableTitle(true, "报名");
                break;
        }
        setOnNavRightListener(new CommonTitleBarView.OnNavRightListener() {
            @Override
            public void onNavRight() {
                String content = mEtContent.getText().toString().trim();
                if (StringUtil.isEmpty(content) || content.length() < 6) {
                    ToastUtil.show("多写点呗！");
                    return;
                }
                SavePublishReq savePublishReq;
                switch (EIntentTagType.valueOf(mIntentTag)) {
                    case TAG_FIND_SHOW://发现-演出
                        savePublishReq = new SavePublishReq(4, content, mMyUserId, mActionId);
                        break;
                    case TAG_FIND_ACTION://发现-活动
                    default:
                        savePublishReq = new SavePublishReq(3, content, mMyUserId, mActionId);
                        break;
                }
                HttpLoader.getInstance().sendRequest(new SavePublishHandler(savePublishReq, new MyHttpResponseListener() {
                    @Override
                    public void onSuccess(Object model) {
                        super.onSuccess(model);
                        if ((Boolean) model) {
                            ToastUtil.show("成功！");
                            SignUpActivity.this.finish();
                        }
                    }
                }, 0));
            }
        });
    }

    @Override
    public void initLayouts() {
        setContentView(R.layout.activity_sign_up);
    }

    @Override
    public void initViews() {
        mEtContent = (EditText) findViewById(R.id.et_content);
    }

    @Override
    public void initListeners() {

    }


}
